package com.example.raspberryPi_demo.entity;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Objects;

/**
 * @author 
 * 
 */
public class CollectedData implements Serializable {
    private Integer timestamp;
    private Integer numberOfSatellites;
    private String latitudeAndLongitude;
    private Integer battery;
    private Integer temperature;
    private String humidity;
    private String atmosphericPressure;
    private String macAddress;
    private String dateTime;//将时间转换成更友好的格式

    private static final long serialVersionUID = 1L;

    public Integer getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(int timestamp) {
        this.timestamp = timestamp;
    }

    public Integer getNumberOfSatellites() {
        return numberOfSatellites;
    }

    public void setNumberOfSatellites(int numberOfSatellites) {
        this.numberOfSatellites = numberOfSatellites;
    }

    public String getLatitudeAndLongitude() {
        return latitudeAndLongitude;
    }

    public void setLatitudeAndLongitude(String latitudeAndLongitude) {
        this.latitudeAndLongitude = latitudeAndLongitude;
    }

    public Integer getBattery() {
        return battery;
    }

    public void setBattery(int battery) {
        this.battery = battery;
    }

    public Integer getTemperature() {
        return temperature;
    }

    public void setTemperature(int temperature) {
        this.temperature = temperature;
    }

    public String getHumidity() {
        return humidity;
    }

    public void setHumidity(String humidity) {
        this.humidity = humidity;
    }

    public String getAtmosphericPressure() {
        return atmosphericPressure;
    }

    public void setAtmosphericPressure(String atmosphericPressure) {
        this.atmosphericPressure = atmosphericPressure;
    }

    public String getMacAddress() {
        return macAddress;
    }

    public void setMacAddress(String macAddress) {
        this.macAddress = macAddress;
    }

    public String getDateTime() {
        return dateTime;
    }

    public void setDateTime(int timestamp) {
        String tempTime;
        tempTime = stampToDate(timestamp);
        this.dateTime = tempTime;
    }

    //将得到的时间戳转换成string，时间格式
    public static String stampToDate(int timestamp) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String time_Date = sdf.format(new Date(timestamp * 1000L));
        return time_Date;
    }


 @Override
    public boolean equals(Object that) {
        if (this == that) {
            return true;
        }
        if (that == null) {
            return false;
        }
        if (getClass() != that.getClass()) {
            return false;
        }
        CollectedData other = (CollectedData) that;
        return (this.getTimestamp() == null ? other.getTimestamp() == null : this.getTimestamp().equals(other.getTimestamp()))
            && (this.getNumberOfSatellites() == null ? other.getNumberOfSatellites() == null : this.getNumberOfSatellites().equals(other.getNumberOfSatellites()))
            && (this.getLatitudeAndLongitude() == null ? other.getLatitudeAndLongitude() == null : this.getLatitudeAndLongitude().equals(other.getLatitudeAndLongitude()))
            && (this.getBattery() == null ? other.getBattery() == null : this.getBattery().equals(other.getBattery()))
            && (this.getTemperature() == null ? other.getTemperature() == null : this.getTemperature().equals(other.getTemperature()))
            && (this.getHumidity() == null ? other.getHumidity() == null : this.getHumidity().equals(other.getHumidity()))
            && (this.getAtmosphericPressure() == null ? other.getAtmosphericPressure() == null : this.getAtmosphericPressure().equals(other.getAtmosphericPressure()))
            && (this.getMacAddress() == null ? other.getMacAddress() == null : this.getMacAddress().equals(other.getMacAddress()))
            && (this.getDateTime() == null ? other.getDateTime() == null : this.getDateTime().equals(other.getDateTime()));
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((getTimestamp() == null) ? 0 : getTimestamp().hashCode());
        result = prime * result + ((getNumberOfSatellites() == null) ? 0 : getNumberOfSatellites().hashCode());
        result = prime * result + ((getLatitudeAndLongitude() == null) ? 0 : getLatitudeAndLongitude().hashCode());
        result = prime * result + ((getBattery() == null) ? 0 : getBattery().hashCode());
        result = prime * result + ((getTemperature() == null) ? 0 : getTemperature().hashCode());
        result = prime * result + ((getHumidity() == null) ? 0 : getHumidity().hashCode());
        result = prime * result + ((getAtmosphericPressure() == null) ? 0 : getAtmosphericPressure().hashCode());
        result = prime * result + ((getMacAddress() == null) ? 0 : getMacAddress().hashCode());
        result = prime * result + ((getDateTime() == null) ? 0 : getDateTime().hashCode());
        return result;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append(" [");
        sb.append("Hash = ").append(hashCode());
        sb.append(", timestamp=").append(timestamp);
        sb.append(", numberofsatellites=").append(numberOfSatellites);
        sb.append(", latitudeandlongitude=").append(latitudeAndLongitude);
        sb.append(", battery=").append(battery);
        sb.append(", temperature=").append(temperature);
        sb.append(", humidity=").append(humidity);
        sb.append(", atmosphericpressure=").append(atmosphericPressure);
        sb.append(", macaddress=").append(macAddress);
        sb.append(", datetime=").append(dateTime);
        sb.append(", serialVersionUID=").append(serialVersionUID);
        sb.append("]");
        return sb.toString();
    }
}